<html>
<head><meta charset="utf-8"><title>Thread-local `GLOBALS` · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html">Thread-local `GLOBALS`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="202944032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944032">(Jul 06 2020 at 00:07)</a>:</h4>
<p>I've never wrapped my head around <code>ast::GLOBALS</code> and <code>span::GLOBALS</code>. Why do they used <code>scoped_thread_local!</code> instead of something more obviously global, like <code>lazy_static!</code>?</p>



<a name="202944149"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944149" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944149">(Jul 06 2020 at 00:11)</a>:</h4>
<p>The code setting this stuff up in librustc_interface/utils.rs doesn't have many comments, which makes understanding it hard</p>



<a name="202944475"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944475" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944475">(Jul 06 2020 at 00:20)</a>:</h4>
<p><span class="user-mention" data-user-id="120989">@njn</span> "global" here is wrt a compilation session, which is isolated to a thread (or a set of threads)</p>



<a name="202944491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944491">(Jul 06 2020 at 00:21)</a>:</h4>
<p>So the name is misleading? Should perhaps be "SessionGlobal" or something?</p>



<a name="202944492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944492">(Jul 06 2020 at 00:21)</a>:</h4>
<p>I know "thread-local" and "global" may seem antithetical but "global" can mean "global to a thread" just fine</p>



<a name="202944529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944529">(Jul 06 2020 at 00:22)</a>:</h4>
<p>I think the name is just used because they're available without being passed around explicitly</p>



<a name="202944536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944536">(Jul 06 2020 at 00:22)</a>:</h4>
<p>"implicit context" might make more sense although I think there's something using that terminology elsewhere</p>



<a name="202944545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944545">(Jul 06 2020 at 00:23)</a>:</h4>
<p>"global to a thread" is nonsensical, IMO. Takes a perfectly common and well-understood word and gives it a subtly different meaning, which is asking for trouble.</p>



<a name="202944549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944549">(Jul 06 2020 at 00:23)</a>:</h4>
<p>well it's "global" in the sense that it's not local to a function</p>



<a name="202944552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944552">(Jul 06 2020 at 00:23)</a>:</h4>
<p>they're "global variables" even if thread-scoped</p>



<a name="202944566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944566">(Jul 06 2020 at 00:24)</a>:</h4>
<p>Let's agree to disagree on that and move on, we could spend all day on this.</p>



<a name="202944597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944597">(Jul 06 2020 at 00:24)</a>:</h4>
<p>Do multiple compiler sessions run in parallel in practice?</p>



<a name="202944600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944600">(Jul 06 2020 at 00:24)</a>:</h4>
<p>meant to say earlier that it would have to be an explicit design decision to disallow them</p>



<a name="202944602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944602">(Jul 06 2020 at 00:24)</a>:</h4>
<p>off the top of my head, <code>rustdoc</code> uses that to build doc tests, and it's possible <code>rls</code> might rely on it too</p>



<a name="202944609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944609">(Jul 06 2020 at 00:25)</a>:</h4>
<p>"disallow them" -- what is "them"?</p>



<a name="202944612"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944612" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944612">(Jul 06 2020 at 00:25)</a>:</h4>
<p>multiple rustc instances in the same process</p>



<a name="202944615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944615">(Jul 06 2020 at 00:25)</a>:</h4>
<p>ok, thanks</p>



<a name="202944661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944661">(Jul 06 2020 at 00:26)</a>:</h4>
<p>in general, good citizenship in Rust is avoiding process-global state to not restrict the user of a library, and rustc executing isolated inside thread(s) that use thread-local state was sort of a natural fit</p>



<a name="202944726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944726">(Jul 06 2020 at 00:29)</a>:</h4>
<p>that doesn't mean we can't break that in order to gain some performance, but if a thread-local is slower than a process-global <code>static</code> when mutation may be involved, that doesn't feel right</p>



<a name="202944776"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944776" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944776">(Jul 06 2020 at 00:30)</a>:</h4>
<p>why not?</p>



<a name="202944792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944792">(Jul 06 2020 at 00:31)</a>:</h4>
<p>my expectation is that the cost of synchronization would outweigh the cost of thread-local accesses but it's possible that the linking model may screw with that</p>



<a name="202944852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202944852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202944852">(Jul 06 2020 at 00:33)</a>:</h4>
<p>for immutable data (whether computed at compile-time or <code>lazy_static!</code> w/o any locks inside), I can see why <code>static</code> would be faster, but I don't think we have anything like that</p>



<a name="202945254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202945254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202945254">(Jul 06 2020 at 00:45)</a>:</h4>
<p>What on earth is <a href="https://github.com/rust-lang/rust/blob/9e6fb538f9254884ca9f958fdce413d6c3f2016c/src/librustc_errors/json/tests.rs#L44">this line</a> doing</p>



<a name="202945258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202945258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202945258">(Jul 06 2020 at 00:45)</a>:</h4>
<p><code>rustc_span::GLOBALS.set(&amp;globals, || rustc_span::GLOBALS.set(&amp;globals, f))</code></p>



<a name="202945306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202945306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202945306">(Jul 06 2020 at 00:46)</a>:</h4>
<p>uhhhhh</p>



<a name="202945308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202945308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202945308">(Jul 06 2020 at 00:47)</a>:</h4>
<p>that's just asking for <code>git blame</code> :P</p>



<a name="202945312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202945312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202945312">(Jul 06 2020 at 00:47)</a>:</h4>
<p>huh? <a href="https://github.com/rust-lang/rust/commit/c31a8754e3f3a9274759cb429aad4ae594d39e29#diff-edeef66fe728ac5916e68f32eb5f0a13R42-R48">https://github.com/rust-lang/rust/commit/c31a8754e3f3a9274759cb429aad4ae594d39e29#diff-edeef66fe728ac5916e68f32eb5f0a13R42-R48</a></p>



<a name="202945315"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202945315" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202945315">(Jul 06 2020 at 00:47)</a>:</h4>
<p>I was expecting to see a rename of one of them</p>



<a name="202945359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202945359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202945359">(Jul 06 2020 at 00:48)</a>:</h4>
<p>looks like it was copied from <code>src/libsyntax/lib.rs</code> at least</p>



<a name="202945365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202945365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202945365">(Jul 06 2020 at 00:49)</a>:</h4>
<p>okay yeah <a href="https://github.com/rust-lang/rust/blob/c31a8754e3f3a9274759cb429aad4ae594d39e29/src/libsyntax/lib.rs#L61-L62">https://github.com/rust-lang/rust/blob/c31a8754e3f3a9274759cb429aad4ae594d39e29/src/libsyntax/lib.rs#L61-L62</a></p>



<a name="202945370"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202945370" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202945370">(Jul 06 2020 at 00:49)</a>:</h4>
<p><span class="user-mention" data-user-id="120989">@njn</span> so yeah it's a mistake, should just have one <code>syntax_pos::GLOBALS.set(...)</code></p>



<a name="202945411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202945411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202945411">(Jul 06 2020 at 00:50)</a>:</h4>
<p>the current line should say:</p>
<div class="codehilite"><pre><span></span><code><span class="n">rustc_span</span>::<span class="n">GLOBALS</span><span class="p">.</span><span class="n">set</span><span class="p">(</span><span class="o">&amp;</span><span class="n">globals</span><span class="p">,</span><span class="w"> </span><span class="n">f</span><span class="p">)</span><span class="w"></span>
</code></pre></div>



<a name="202945593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202945593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202945593">(Jul 06 2020 at 00:57)</a>:</h4>
<p>I think somebody got confused by the fact that <code>rustc_span::GLOBALS</code> is nested within <code>rustc_ast::GLOBALS</code>, and so there are other lines that do look a bit like that, but which refer to two different <code>GLOBALS</code></p>



<a name="202945595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202945595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202945595">(Jul 06 2020 at 00:57)</a>:</h4>
<p>/me is gonna fix that, too</p>



<a name="202946549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202946549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202946549">(Jul 06 2020 at 01:27)</a>:</h4>
<p>/me files <a href="https://github.com/rust-lang/rust/pull/74079">https://github.com/rust-lang/rust/pull/74079</a></p>



<a name="202950521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202950521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202950521">(Jul 06 2020 at 03:23)</a>:</h4>
<p>Hmm, <code>./x.py test</code> does not run the tests in <code>librustc_span/symbol/tests.rs</code>, it seems</p>



<a name="202953846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202953846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202953846">(Jul 06 2020 at 05:04)</a>:</h4>
<p>Why does the compiler have both the (session-specific) <code>Globals</code> and also <code>ImplicitCtxt</code>? Seems like they are similar things</p>



<a name="202953932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202953932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202953932">(Jul 06 2020 at 05:07)</a>:</h4>
<p>but <code>Globals</code> can only be accessed via TLS, but <code>ImplicitCtxt</code> is a way of getting the <code>GlobalCtxt</code> via TLS, but the <code>GlobalCtxt</code> can also be gotten by passing it around?</p>



<a name="202954274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202954274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202954274">(Jul 06 2020 at 05:16)</a>:</h4>
<p>the amount of plumbing around this stuff and all the other top-level compiler stuff... yikes</p>



<a name="202954350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202954350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202954350">(Jul 06 2020 at 05:18)</a>:</h4>
<p>all these various <code>enter</code> functions</p>



<a name="202955898"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202955898" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202955898">(Jul 06 2020 at 06:01)</a>:</h4>
<p><span class="user-mention" data-user-id="120989">@njn</span> this used to be really simple but then people started copying the one thing I did and it devolved into this, lol</p>



<a name="202955962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202955962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202955962">(Jul 06 2020 at 06:03)</a>:</h4>
<p>IIRC the important part is that <code>ImplicitCtxt</code> carries more information than the <code>TyCtxt</code>, but maybe it doesn't anymore?</p>



<a name="202955968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202955968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202955968">(Jul 06 2020 at 06:03)</a>:</h4>
<p>I thought it was important to parallel queries</p>



<a name="202955977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202955977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202955977">(Jul 06 2020 at 06:03)</a>:</h4>
<p>It has a little bit extra, compared to <code>TyCtxt</code></p>



<a name="202956024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202956024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202956024">(Jul 06 2020 at 06:04)</a>:</h4>
<p>that extra is why it exists as opposed to just being "<code>TyCtxt</code> in TLS for the odd thing that can't get it any other way"</p>



<a name="202957334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202957334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202957334">(Jul 06 2020 at 06:38)</a>:</h4>
<p>there are so many layers of closure wrapping in this startup code I can't even work out a notation to write them down</p>



<a name="202958279"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202958279" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202958279">(Jul 06 2020 at 06:58)</a>:</h4>
<p>AFAIK the other reason for having multiple sessions in one process would be parallel compilation.</p>



<a name="202959150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202959150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202959150">(Jul 06 2020 at 07:15)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> my understanding is that parallel compilation occurs within a Session</p>



<a name="202959159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202959159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202959159">(Jul 06 2020 at 07:15)</a>:</h4>
<p>e.g. a single session might have multiple threads</p>



<a name="202959671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202959671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202959671">(Jul 06 2020 at 07:24)</a>:</h4>
<p>Ah, interesting, I didn't realize that.</p>



<a name="202964360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/202964360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#202964360">(Jul 06 2020 at 08:27)</a>:</h4>
<p>You might have two sessions running at the same time, one for normal compilation, one for rustdocs</p>



<a name="203028236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203028236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203028236">(Jul 06 2020 at 19:04)</a>:</h4>
<p>I wonder if it's possible to keep all data from those globals in a <code>ParseSess</code>, or <code>Session</code>, or some new session type and provide TLS-based access to the <em>whole session</em> type for exceptional cases like <code>Debug</code> impls, etc.</p>



<a name="203028252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203028252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203028252">(Jul 06 2020 at 19:04)</a>:</h4>
<p>Something like <code>ImplicitCtxt</code> but for early compilation.</p>



<a name="203028546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203028546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203028546">(Jul 06 2020 at 19:07)</a>:</h4>
<p>Without a sensible and documented design here things gradually descent into chaos with PRs like <a href="https://github.com/rust-lang/rust/pull/72618">https://github.com/rust-lang/rust/pull/72618</a>, which do bring some specific improvements but bring equal or perhaps larger amount of harm to the general  compiler architecture health (cc <span class="user-mention" data-user-id="125294">@Aaron Hill</span> ).</p>



<a name="203030650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203030650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203030650">(Jul 06 2020 at 19:28)</a>:</h4>
<p>I'm curious, is the use of TLS here a performance win or a performance loss?</p>



<a name="203030676"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203030676" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203030676">(Jul 06 2020 at 19:29)</a>:</h4>
<p>Hypothetically, would passing it around as a parameter help or hurt?</p>



<a name="203031957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203031957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203031957">(Jul 06 2020 at 19:42)</a>:</h4>
<p>purely from a performance POV, not taking developer ergonomics into account?</p>



<a name="203031993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203031993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203031993">(Jul 06 2020 at 19:42)</a>:</h4>
<p>~A performance loss.<br>
Here's a specific example of moving the current edition from globals to <code>ParseSess</code> - <a href="https://github.com/rust-lang/rust/pull/59742">https://github.com/rust-lang/rust/pull/59742</a>.</p>



<a name="203032082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203032082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203032082">(Jul 06 2020 at 19:43)</a>:</h4>
<p>The problem is that it's sometime impossible or really impractical to carry the session around as an argument (such cases are not common though).</p>



<a name="203032326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203032326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203032326">(Jul 06 2020 at 19:46)</a>:</h4>
<p>A nice thing is that things like <code>ParseSess</code> are already carried around in majority of code (you need it to report compiler errors, for example), so you don't even need to do any extra work.</p>



<a name="203033622"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203033622" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203033622">(Jul 06 2020 at 19:59)</a>:</h4>
<p>to be clear, the <em>only</em> usecases I had in mind for TLS <code>TyCtxt</code> were <code>fmt::Debug</code>/<code>fmt::Display</code> impls and <code>bug!(...)</code> / <code>span_bug!(...)</code> ICEs (but it's optional there, and just improves the output quality slightly. if it's even a thing anymore)</p>



<a name="203033786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203033786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203033786">(Jul 06 2020 at 20:00)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> <a href="https://github.com/rust-lang/rust/issues/59472">#59472</a> is something I was looking at yesterday. It seems like that setting of the source map could be done as part of the standard Globals initialization, just by moving things around a bit. I'm going to try to do that now</p>



<a name="203033827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203033827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203033827">(Jul 06 2020 at 20:00)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> so it was mostly intended for cases in which you more or less can't pass contexts around due to (libstd) APIs, but there were some deviations from that sadly</p>



<a name="203033975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203033975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203033975">(Jul 06 2020 at 20:01)</a>:</h4>
<p>IIRC the way I did <code>fmt::Debug</code> impls when the type is defined in a crate which can't access the TLS content directly is have a TLS var that holds a <code>fn</code> pointer for the <code>fmt::Debug</code> implementation. this was before any <code>GLOBALS</code> variables were added, although I think we might've had the string interner in TLS since forever</p>



<a name="203034168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203034168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203034168">(Jul 06 2020 at 20:03)</a>:</h4>
<p>maybe we can scope access to the TLS vars that refer to contexts in such a way that only <code>fmt::Debug</code> type stuff has access to it</p>



<a name="203034466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203034466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203034466">(Jul 06 2020 at 20:05)</a>:</h4>
<p>sadly due to HRTB lifetime interactions with associated types, I'm not sure it's possible to make a generic function that handles any type that implements <code>ty::Print</code>, which would probably be the easy way to hide the TLS <code>TyCtxt</code></p>



<a name="203035061"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203035061" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203035061">(Jul 06 2020 at 20:10)</a>:</h4>
<p><code>Decode</code> impls are a similar case</p>



<a name="203036786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203036786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203036786">(Jul 06 2020 at 20:27)</a>:</h4>
<p>Here's my attempt to capture all the layers of wrapping within<code>run_compiler</code>: <a href="https://paste.mozilla.org/gJeRK82j/raw">https://paste.mozilla.org/gJeRK82j/raw</a></p>



<a name="203036877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203036877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203036877">(Jul 06 2020 at 20:28)</a>:</h4>
<p>we call <code>with_globals</code>, then create a <code>Compiler</code> and <code>Session</code>, then set the <code>source_map</code>. Seems like that could be done more nicely</p>



<a name="203037503"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203037503" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203037503">(Jul 06 2020 at 20:34)</a>:</h4>
<p>ugh we should get around to implementing our own serialization traits already so we can stop having to do unsound specialization hacks</p>



<a name="203037554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203037554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203037554">(Jul 06 2020 at 20:35)</a>:</h4>
<p>TLS shouldn't be needed at all, either way, for deserialization</p>



<a name="203037796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203037796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203037796">(Jul 06 2020 at 20:37)</a>:</h4>
<p>@eddyb: what about symbol interning?</p>



<a name="203039029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203039029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203039029">(Jul 06 2020 at 20:48)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> <a href="https://github.com/rust-lang/rust/pull/73851">https://github.com/rust-lang/rust/pull/73851</a> gets rid of most of the specialization for serialization</p>



<a name="203040060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203040060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203040060">(Jul 06 2020 at 21:00)</a>:</h4>
<p><span class="user-mention" data-user-id="120989">@njn</span> we can still require that <code>Symbol</code> is decoded with a contextful decoder, should be fine for most situations</p>



<a name="203040108"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203040108" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203040108">(Jul 06 2020 at 21:00)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> thanks</p>



<a name="203040584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203040584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203040584">(Jul 06 2020 at 21:05)</a>:</h4>
<p>oh it actually introduces new derives</p>



<a name="203040626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203040626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203040626">(Jul 06 2020 at 21:05)</a>:</h4>
<p>Could <a href="https://github.com/rust-lang/rust/blob/0c04344d86f9598f20d9ec86fe87ea2a5d6ff8e6/src/librustc_interface/interface.rs#L190-L196">this code</a> just be written as:</p>
<div class="codehilite"><pre><span></span><code>let r = f(&amp;compiler);
compiler.sess.finish_diagnostics(registry);
</code></pre></div>


<p>?</p>



<a name="203040728"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203040728" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203040728">(Jul 06 2020 at 21:06)</a>:</h4>
<p>whenever you see that pattern, it's almost always because of panics</p>



<a name="203040776"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203040776" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203040776">(Jul 06 2020 at 21:07)</a>:</h4>
<p>based on the name <code>_sess_abort_error</code> I'd say  it needs to be like that</p>



<a name="203040787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203040787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203040787">(Jul 06 2020 at 21:07)</a>:</h4>
<p>how are panics relevant?</p>



<a name="203040810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203040810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203040810">(Jul 06 2020 at 21:07)</a>:</h4>
<p>fatal errors and ICEs are panics</p>



<a name="203040869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203040869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203040869">(Jul 06 2020 at 21:08)</a>:</h4>
<p>does it ensure that finish_diagnostics is run on a panic?</p>



<a name="203040879"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203040879" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203040879">(Jul 06 2020 at 21:08)</a>:</h4>
<p>there's not really any other way to stop compilation (short of <code>process::exit</code>)</p>



<a name="203040884"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203040884" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203040884">(Jul 06 2020 at 21:08)</a>:</h4>
<p>yes, that's the idea</p>



<a name="203040910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203040910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203040910">(Jul 06 2020 at 21:08)</a>:</h4>
<p>yeah that's what I meant earlier, "drop guards" like that are almost always for panics</p>



<a name="203040916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203040916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203040916">(Jul 06 2020 at 21:08)</a>:</h4>
<p>ok, thanks</p>



<a name="203050100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203050100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203050100">(Jul 06 2020 at 22:51)</a>:</h4>
<p>hmm, the source_map isn't set up for each rayon thread in a parallel rustc</p>



<a name="203050295"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203050295" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203050295">(Jul 06 2020 at 22:53)</a>:</h4>
<p>Ah, this is such spaghetti. I want to simplify it but I can't find the first loose piece to start tugging on</p>



<a name="203050362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203050362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203050362">(Jul 06 2020 at 22:54)</a>:</h4>
<p>The fact that rustdoc calls into all this startup stuff in a different way to the main compiler is a real complication</p>



<a name="203052424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203052424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203052424">(Jul 06 2020 at 23:20)</a>:</h4>
<p>Hmm, why do we spin up a separate thread for compilation in the non-parallel rustc?</p>



<a name="203054768"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203054768" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203054768">(Jul 06 2020 at 23:57)</a>:</h4>
<p>IIRC, the lack of control over the stack size in the main thread</p>



<a name="203057284"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203057284" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203057284">(Jul 07 2020 at 00:42)</a>:</h4>
<p>What's wrong with the default size?</p>



<a name="203061300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203061300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203061300">(Jul 07 2020 at 02:13)</a>:</h4>
<p>/me wonders the difference between <code>scoped_thread</code> and a more normal thread spawning</p>



<a name="203063114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203063114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203063114">(Jul 07 2020 at 03:04)</a>:</h4>
<p>hmm, no <code>'static</code> bounds</p>



<a name="203063246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203063246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203063246">(Jul 07 2020 at 03:08)</a>:</h4>
<p>hmm, maybe that's what the "scoped" means... it's known to be joined to immediately after spawning</p>



<a name="203063254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203063254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203063254">(Jul 07 2020 at 03:08)</a>:</h4>
<p>Great fodder for a comment, methinks</p>



<a name="203073831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203073831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203073831">(Jul 07 2020 at 07:31)</a>:</h4>
<p>With stacker, we should be able to remove that thread</p>



<a name="203082400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203082400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203082400">(Jul 07 2020 at 09:23)</a>:</h4>
<p>What is stacker?</p>



<a name="203082484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203082484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203082484">(Jul 07 2020 at 09:24)</a>:</h4>
<p><a href="https://github.com/rust-lang/stacker">https://github.com/rust-lang/stacker</a>, presumably</p>



<a name="203083829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203083829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203083829">(Jul 07 2020 at 09:42)</a>:</h4>
<p>Yes</p>



<a name="203140688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203140688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203140688">(Jul 07 2020 at 18:27)</a>:</h4>
<p><span class="user-mention" data-user-id="211727">@Jonas Schievink</span> hmm for some reason I thought the main thread would make that hard but I guess not necessarily</p>



<a name="203140704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203140704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203140704">(Jul 07 2020 at 18:27)</a>:</h4>
<p>so we replace <code>thread::spawn</code> by <code>catch_unwind</code>?</p>



<a name="203140724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203140724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203140724">(Jul 07 2020 at 18:27)</a>:</h4>
<p>(well, scoped threads because threads pools etc.)</p>



<a name="203140882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203140882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203140882">(Jul 07 2020 at 18:28)</a>:</h4>
<p>I wonder if there are soundness issues regarding things that don't have lifetime parameters but can't be sent between threads, I remember one aspect of having "subordinate" threads meant that we could own something in the parent thread, and the child thread could never UAF it</p>



<a name="203140901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203140901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203140901">(Jul 07 2020 at 18:28)</a>:</h4>
<p>whereas with <code>thread_local!</code> you can't guarantee that</p>



<a name="203141024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203141024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203141024">(Jul 07 2020 at 18:30)</a>:</h4>
<p>(because you could have a different <code>thread_local!</code> that has a destructor with a value that would be UAF if it's ran after the destructor of the <code>thread_local!</code> that owns the actual data)</p>



<a name="203141117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203141117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203141117">(Jul 07 2020 at 18:30)</a>:</h4>
<p>You could use <code>scoped_thread_local!</code> combined with requiring a <code>Send</code> bound for the closure that would otherwise run in a new thread.</p>



<a name="203141141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203141141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203141141">(Jul 07 2020 at 18:30)</a>:</h4>
<p>no, you can't, for this situation</p>



<a name="203141225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203141225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203141225">(Jul 07 2020 at 18:31)</a>:</h4>
<p>this is about something like using a non-Sync/Send wrapper around a <code>&amp;'static str</code> to represent an interned string</p>



<a name="203141312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203141312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203141312">(Jul 07 2020 at 18:32)</a>:</h4>
<p>where there is no connection between the owner of the data and users of the values</p>



<a name="203141345"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203141345" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203141345">(Jul 07 2020 at 18:32)</a>:</h4>
<p>That is why the <code>Send</code> bound for the closure is necessary despite not running in a different thread.</p>



<a name="203141444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203141444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203141444">(Jul 07 2020 at 18:33)</a>:</h4>
<p>one "fun" way in which you can handle this is have the <code>rustc</code> executable start <code>rustc_driver</code> in a specific way that leaks an object (basically creating a <code>&amp;'static mut Foo</code>) and anything that uses multiple threads would take a different path to spawning the compiler threads</p>



<a name="203141556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203141556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203141556">(Jul 07 2020 at 18:34)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span> the problem is that there is nothing preventing you from sticking this <code>BadInternedString</code> into a thread-local, which will outlive the backing storage</p>



<a name="203141584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203141584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203141584">(Jul 07 2020 at 18:34)</a>:</h4>
<p>I can write an example if you want?</p>



<a name="203141606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203141606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203141606">(Jul 07 2020 at 18:34)</a>:</h4>
<p>I get it.</p>



<a name="203141627"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203141627" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203141627">(Jul 07 2020 at 18:34)</a>:</h4>
<p>this is basically a sketchy pattern that only is sound (maybe not even then, not sure0 if you have a separate thread</p>



<a name="203141661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203141661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203141661">(Jul 07 2020 at 18:35)</a>:</h4>
<p>because then there is no way to escape such a value outside of that thread, and you have a point at which you know it's all dead</p>



<a name="203141779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203141779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203141779">(Jul 07 2020 at 18:36)</a>:</h4>
<p>you could imagine using threads as "global arenas" where you don't have to use lifetimes but you also can't pass data between threads</p>



<a name="203141801"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203141801" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203141801">(Jul 07 2020 at 18:36)</a>:</h4>
<p>but anyway it's possible we don't do anything like this anymore (if we ever did? I think we did)</p>



<a name="203141823"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203141823" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203141823">(Jul 07 2020 at 18:36)</a>:</h4>
<p>I just don't know how to properly check for it</p>



<a name="203141841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203141841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203141841">(Jul 07 2020 at 18:36)</a>:</h4>
<p>presumably look for non-<code>Sync</code>/<code>Send</code> wrappers around pointers/references?</p>



<a name="203141855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203141855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203141855">(Jul 07 2020 at 18:37)</a>:</h4>
<p>that don't have lifetime parameters</p>



<a name="203141876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203141876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203141876">(Jul 07 2020 at 18:37)</a>:</h4>
<p>so they're effectively "<code>'static</code> within a thread"</p>



<a name="203142018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203142018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203142018">(Jul 07 2020 at 18:38)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60/near/203141801">said</a>:</p>
<blockquote>
<p>but anyway it's possible we don't do anything like this anymore (if we ever did? I think we did)</p>
</blockquote>
<p>I you mean <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/symbol/struct.SymbolStr.html"><code>SymbolStr</code></a>.</p>



<a name="203142145"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203142145" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203142145">(Jul 07 2020 at 18:39)</a>:</h4>
<p>lol <a href="https://github.com/rust-lang/rust/blob/e1beee4992ad4b235fc700bf7af1ee86f894ea53/src/librustc_span/symbol.rs#L1401-L1402">https://github.com/rust-lang/rust/blob/e1beee4992ad4b235fc700bf7af1ee86f894ea53/src/librustc_span/symbol.rs#L1401-L1402</a></p>



<a name="203142224"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203142224" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203142224">(Jul 07 2020 at 18:40)</a>:</h4>
<p>anyway yeah I should've just looked this up, seems like this is the only instance</p>



<a name="203142446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203142446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203142446">(Jul 07 2020 at 18:42)</a>:</h4>
<p><span class="user-mention" data-user-id="120989">@njn</span> so if you want to get rid of a separate thread in some cases, you have to make sure that one of two things happen:</p>
<ol>
<li>a separate thread (which you'd have anyway if you were running multiple rustc threads, I think?) owns the interner</li>
<li>the interner lives forever (only really doable for the <code>rustc</code> executable. <code>Box::leak</code> is an easy way to do that, at least)</li>
</ol>



<a name="203211219"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203211219" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203211219">(Jul 07 2020 at 22:28)</a>:</h4>
<p>@eddyb: thanks for the info, I don't think it's worth it, the potential clean-up here isn't that big.</p>



<a name="203211255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203211255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203211255">(Jul 07 2020 at 22:29)</a>:</h4>
<p>The unsafety of that interner setup has always bothered me. It's part of the reason I spent some time cleaning up the symbol stuff, greatly reducing the capabitilies and use of <code>SymbolStr</code>.</p>



<a name="203211265"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203211265" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203211265">(Jul 07 2020 at 22:29)</a>:</h4>
<p>Didn't manage to get rid of it completely, alas.</p>



<a name="203211484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Thread-local%20%60GLOBALS%60/near/203211484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Thread-local.20.60GLOBALS.60.html#203211484">(Jul 07 2020 at 22:32)</a>:</h4>
<p>It's possible to eliminate it in theory, and just use <code>Symbol::with()</code> every time we need access to the chars themselves. But in practice it's a huge pain, introducing tons of annoying closures.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>